package com.blog1.common.util;


import com.blog1.pojo.dataobject.BlogInfo;
import com.blog1.pojo.dataobject.UserInfo;
import com.blog1.pojo.response.BlogInfoListResult;
import com.blog1.pojo.response.BlogInfoResult;
import com.blog1.pojo.response.LoginResult;
import com.blog1.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;

import java.util.HashMap;
import java.util.Map;

public class BeanTransUtils {
    public static BlogInfoListResult trans(BlogInfo blogInfo){
        if(blogInfo == null){
            return null;
        }
        BlogInfoListResult result = new BlogInfoListResult();
        BeanUtils.copyProperties(blogInfo,result);
        result.setTime(blogInfo.getCreateTime());
        return result;
    }

    public static BlogInfoResult trans1(BlogInfo blogInfo){
        if(blogInfo == null){
            return null;
        }
        BlogInfoResult result = new BlogInfoResult();
        BeanUtils.copyProperties(blogInfo,result);
        result.setTime(blogInfo.getUpdateTime());
        return result;
    }

    public static LoginResult trans(UserInfo userInfo) {
    LoginResult result=new LoginResult();
    result.setUserId(userInfo.getId());
        Map<String, Object> map = new HashMap<>();
        map.put("id", userInfo.getId());
        map.put("userName",userInfo.getUsername());
    result.setToken(JwtUtils.createToken(map));
    return result;
    }

    public static UserInfoResponse trans2(UserInfo userInfo) {
        UserInfoResponse userInfoResponse=new UserInfoResponse();
        BeanUtils.copyProperties(userInfo,userInfoResponse);
        return userInfoResponse;
    }




}
